package com.red.controller.admin;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.red.entity.Carousels;
import com.red.mapper.AttractionsMapper;
import com.red.mapper.CarouselsMapper;
import com.red.result.Result;
import com.red.vo.CarouselsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/admin/carousels")
@CrossOrigin
public class CarouselsController {

    @Autowired
    private CarouselsMapper carouselsMapper;

    /**
     * 查询所有轮播图信息
     * @return
     */
    @GetMapping("/all")
    public Result<List<CarouselsVO>> selectAll(){

        List<CarouselsVO> carousels = carouselsMapper.selectAll();
        return Result.success(carousels);
    }

    /**
     * 新增轮播图
     * @param carousels
     * @return
     */
    @PostMapping("/insert")
    public Result insert(@RequestBody Carousels carousels){
        carouselsMapper.insert(carousels);
        return Result.success();
    }

    /**
     * 修改首页轮播图
     * @param carousels
     * @return
     */
    @PostMapping("/update")
    public Result update(@RequestBody Carousels carousels){
        carouselsMapper.updateById(carousels);
        return Result.success();
    }

    /**
     * 删除首页轮播图
     * @param ids
     * @return
     */
    @DeleteMapping("/{ids}")
    public Result deleteById(@PathVariable List<Long> ids){
        carouselsMapper.deleteByIds(ids);
        return Result.success();
    }
}
